/*
 * Created by JFormDesigner on Fri Jun 28 14:31:54 CST 2024
 */

package scct.sun.ui;

import scct.sun.dao.TypeDao;
import scct.sun.model.GoodsType;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.util.List;
/**
 * @author syjyy
 */
public class PanelType extends JPanel {
    FormMain main;
   DefaultTableModel model;
    public PanelType(FormMain formMain) {
        initComponents();
        this.main=formMain;
        initView();
    }
    
    public void initView(){
        model=(DefaultTableModel) tabType.getModel();
        model.addColumn("id");
        model.addColumn("类别名称");
        model.addColumn("类别说明");
        getTable();
    }
    public void getTable(){
        model.setRowCount(0);
        TypeDao typeDao=new TypeDao();
       List<GoodsType> allTyps=typeDao.getAllTyps();
       for (GoodsType allTyp : allTyps){
           model.addRow(new Object[]{allTyp.getId(),allTyp.getName(),allTyp.getRemark()});
       }
    }

    private void btnAdd(ActionEvent e) {
        // TODO add your code here
        DlgAddType dlgAddType = new DlgAddType(main);
        dlgAddType.setModal(true);
        dlgAddType.setVisible(true);
        getTable();
    }
    
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - sunyujie
        panel1 = new JPanel();
        btnAdd = new JButton();
        btnUpdate = new JButton();
        scrollPane1 = new JScrollPane();
        tabType = new JTable();

        //======== this ========
        setBorder ( new javax . swing. border .CompoundBorder ( new javax . swing. border .TitledBorder ( new javax .
        swing. border .EmptyBorder ( 0, 0 ,0 , 0) ,  "JF\u006frmD\u0065sig\u006eer \u0045val\u0075ati\u006fn" , javax. swing .border
        . TitledBorder. CENTER ,javax . swing. border .TitledBorder . BOTTOM, new java. awt .Font ( "Dia\u006cog"
        , java .awt . Font. BOLD ,12 ) ,java . awt. Color .red ) , getBorder
        () ) );  addPropertyChangeListener( new java. beans .PropertyChangeListener ( ){ @Override public void propertyChange (java
        . beans. PropertyChangeEvent e) { if( "\u0062ord\u0065r" .equals ( e. getPropertyName () ) )throw new RuntimeException
        ( ) ;} } );
        setLayout(new BorderLayout());

        //======== panel1 ========
        {
            panel1.setLayout(new FlowLayout(FlowLayout.RIGHT));

            //---- btnAdd ----
            btnAdd.setText("\u65b0\u589e\u7c7b\u522b");
            btnAdd.addActionListener(e -> btnAdd(e));
            panel1.add(btnAdd);

            //---- btnUpdate ----
            btnUpdate.setText("\u4fee\u6539\u7c7b\u522b");
            panel1.add(btnUpdate);
        }
        add(panel1, BorderLayout.NORTH);

        //======== scrollPane1 ========
        {
            scrollPane1.setViewportView(tabType);
        }
        add(scrollPane1, BorderLayout.CENTER);
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - sunyujie
    private JPanel panel1;
    private JButton btnAdd;
    private JButton btnUpdate;
    private JScrollPane scrollPane1;
    private JTable tabType;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
